import 'package:aichat_flutter_wallet/module_common/utils/colors.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class BottomBtn extends StatefulWidget {
  final Color color;
  List<String> textList = ['Confirm'];
  final Function? onConfirm;
  final Function? onCancel;
  Color? disableColor = AppColors.c_ffffff30;
  bool disable;
  final Function? onDisableClick;
  bool isEvent; // 两个按钮的时候是否大小一样
  double height = 46;

  BottomBtn({
    Key? key,
    this.color = AppColors.c_8667FE,
    required this.textList,
    this.onConfirm = null,
    this.onCancel,
    this.disable = false,
    this.onDisableClick,
    this.isEvent = true,
    this.disableColor,
    this.height = 46,
  }) : super(key: key);

  @override
  State<BottomBtn> createState() => _BottomBtnState();
}

class _BottomBtnState extends State<BottomBtn> {
  Widget getChild() {
    if (widget.textList.length == 1) {
      return GestureDetector(
        onTap: () {
          if (widget.onConfirm != null && !widget.disable) {
            widget.onConfirm!.call();
          }
          if (widget.disable && widget.onDisableClick != null) {
            widget.onDisableClick!.call();
          }
        },
        child: Container(
          height: widget.height.w,
          // width: 335,
          alignment: Alignment.center,
          decoration: BoxDecoration(color: AppColors.c_8667FE, borderRadius: BorderRadius.circular(10.w)),
          child: Text(
            '${widget.textList[0]}',
            style: TextStyle(
                color: widget.disable ? AppColors.c_ffffff30 : AppColors.c_white,
                fontSize: 14.sp,
                fontWeight: FontWeight.w400),
          ),
        ),
      );
    } else {
      return Container(
        // width: 335,
        height: widget.height,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Expanded(
              flex: 1,
              child: GestureDetector(
                onTap: () {
                  if (widget.onCancel != null) {
                    widget.onCancel!.call();
                  }
                },
                child: Container(
                    // height: 55,
                    // width: widget.isEvent ? 157 : 110,
                    decoration: BoxDecoration(color: AppColors.c_F6F3FF, borderRadius: BorderRadius.circular(8.w)),
                    child: Align(
                        alignment: Alignment.center,
                        child: Text(
                          widget.textList[0],
                          style: TextStyle(color: AppColors.c_1D0061, fontSize: 14.sp, fontWeight: FontWeight.w500),
                        ))),
              ),
            ),
            SizedBox(
              width: 20.w,
            ),
            Expanded(
              flex: widget.isEvent ? 1 : 2,
              child: GestureDetector(
                onTap: () {
                  if (widget.onConfirm != null && !widget.disable) {
                    widget.onConfirm!.call();
                  }
                  if (widget.disable && widget.onDisableClick != null) {
                    widget.onDisableClick!.call();
                  }
                },
                child: Container(
                  // height: 55,
                  width: widget.isEvent ? 157.w : 215.w,
                  decoration: BoxDecoration(color: AppColors.c_8667FE, borderRadius: BorderRadius.circular(8.w)),
                  child: Align(
                    alignment: Alignment.center,
                    child: Text(
                      widget.textList[1],
                      style: TextStyle(
                        color: widget.disable ? AppColors.c_ffffff30 : AppColors.c_white,
                        fontWeight: FontWeight.w400,
                        fontSize: 14.sp,
                      ),
                    ),
                  ),
                ),
              ),
            )
          ],
        ),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return getChild();
  }
}
